package cn.zengdeai.langchain4j_springboot.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
@Tag(name = "Hello API", description = "提供简单的问候接口")
public class HelloController {

    @PostMapping("/hello")
    @Operation(summary = "发送问候请求", description = "根据提供的名称返回问候语", responses = {
            @ApiResponse(responseCode = "200", description = "成功响应", content = @Content(schema = @Schema(implementation = GreetingResponse.class))),
            @ApiResponse(responseCode = "400", description = "无效输入", content = @Content)
    })
    public GreetingResponse sayHello(@RequestBody NameInput input) {
        if (input == null || input.getName() == null || input.getName().trim().isEmpty()) {
            throw new IllegalArgumentException("Name cannot be empty");
        }
        return new GreetingResponse("Hello, " + input.getName() + "!");
    }

    // 请求体类
    public static class NameInput {
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    // 响应体类
    public static class GreetingResponse {
        private String message;

        public GreetingResponse(String message) {
            this.message = message;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }
    }
}
